class Solution {
public:
    bool checkPalindromeFormation(string a, string b) {
        int left = a.size() / 2 - 1;
        left = min(check(a, a, left), check(b, b, left));
        left = min(check(a, b, left), check(b, a, left));
        return left == -1;
    }
    int check(string s1,string s2,int left){
        int right = s2.size() - left - 1;
        while(left >= 0 && right < s2.size()){
            if(s1[left] != s2[right]){
                break;
            }
            left--;
            right++;
        }
        return left;
    }
};
